package com.upb.webserver.chainorg;

import cn.hutool.core.collection.CollectionUtil;
import com.upb.webserver.common.tools.JsonUtils;
import com.upb.webserver.common.tools.MybatisExampleTools;
import com.upb.webserver.dao.entity.TbChainHost;
import com.upb.webserver.dao.entity.TbChainHostExample;
import com.upb.webserver.dao.entity.TbChainOrg;
import com.upb.webserver.dao.entity.TbChainOrgExample;
import com.upb.webserver.dao.mapper.TbChainOrgMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ChainOrgManager {
    @Autowired
    private TbChainOrgMapper chainOrgMapper;


    /**
     * @param chainId
     * @return
     */
    public List<Integer> listOrgIdByChainId(int chainId) {
        log.info("start exec method [getOrgIdListByChainId]. chainId:{}", chainId);
        //get orgId
        List<TbChainOrg> tbChainOrgList = chainOrgMapper.ListByChainId(chainId);
        if (CollectionUtil.isEmpty(tbChainOrgList)) {
            log.info("fail exec method [sendMessageAfterDeveloperDeleteChain].  not found chain-org record by chainId:{} ", chainId);
            return Collections.EMPTY_LIST;
        }
        List<Integer> orgIdList = tbChainOrgList.stream()
                .map(co -> co.getOrgId())
                .collect(Collectors.toList());

        log.info("success exec method [getOrgIdListByChainId]. chainId:{} result:{}", chainId, JsonUtils.objToString(orgIdList));
        return orgIdList;
    }

}
